export interface ListChatModel {
    // 用户id
    id?: number
    chatId?: number
    title?: string
    token?:string | null
    pageNum?: number
    pageSize?: number
    content?: string
}
export interface ChatMessage {
    mId?: number
    chatId?: number
    role?: string
    content?: string
    createTime?: string
    chatType?:Number
    knowledgeBaseName?:string
    list?:knowledgeList[]
}

export interface knowledgeList {
    docId: Number
    source: string
    pageContent: string
}

interface queryHistory {
    token?:string | null
    id?: number,
    chatId?: number
    title?: string
    pageNum?: number
    pageSize?: number
    content?: string
}

interface knowledgeDoc {
    id?: number 
    token?:string | null
    chatId?: number
    content?: string
    knowledgeBaseName?: string
}



// 根据用户id分页查询对话母表记录
export async function getHistory(params:ListChatModel) {
    let data:queryHistory = {
        id:params.id,
        pageNum:params.pageNum,
        pageSize:params.pageSize
    }
    return useGet<any>('/history/queryByPage', data, 
    {
        token: true,
        customDev: true,
        loading: false
    })
}

// 根据用户id新建目标记录
export async function addConversion(params:ListChatModel) {
    let data:queryHistory = {
        id:params.id,
        title:'新建聊天'
    }
    return usePost<any>('/history/addConversion',data,
    {
        token:true,
        customDev:true,
        loading:false
    }
    )
}

// 根据对话记录目标id查询所有对话
export async function findConversion(params:ListChatModel) {
    let data:queryHistory = {
        chatId:params.chatId
    }
    return useGet<any>('/chat/findConversionByChatId',data,
    {
        token: true,
        customDev: true,
        loading: false
    })
}

// 修改对话记录母表标题
export async function editTitle(params:ListChatModel) {
    let data:queryHistory = {
        chatId:params.chatId,
        title:params.title
    }
    return usePut<any>('/history/updateTitleByChatId', data, 
    {
        token: true,
        customDev: true,
        loading: false
    })
}

// 删除对话母表和子表记录
export async function deleteTitle(params:ListChatModel) {
    let data:queryHistory = {
        chatId:params.chatId,
        title:params.title
    }
    return useDelete<any>(`/history/deleteByChatId?chatId=${data.chatId}&title=${data.title}`, null, 
    {
        token: true,
        customDev: true,
        loading: false
    })
}

// 删除用户所有对话目标和子表
export async function deleteAllTitle(params:ListChatModel) {
    let data:queryHistory = {
        id:params.id
    }
    return useDelete<any>(`/history/deleteAllByUserId?id=${data.id}`, null, 
    {
        token: true,
        customDev: true,
        loading: false
    })
}


// 发送消息
export async function sendChat(params:ListChatModel) {
    let data:queryHistory = {
        token:localStorage.getItem('Authorization'),
        id:params.id,
        chatId:params.chatId,
        content:params.content
        
    }
    return usePost<any>('/chat/sendMessage', data, 
    {
        token: true,
        customDev: true,
        loading: false
    })
}

// 返回知识库命中文档
export async function docList(params:any) {
    return useGet<any>('/chat/returnDocList?chatId='+ params,null,
    {
        token: true,
        customDev: true,
        loading: false        
    })
}

export function findKnowledgeById(params:string) {
    return useGet<any>('/knowledge/findKnowledgeByToken?token='+params,null,
    {
      token: true,
      loading:false,
      customDev:true,
    })
  }

export function findDownloadUrl(params: any) {
    return useGet<any>('/chat/returnDocUrl?docId='+params.docId+'&token='+params.token,null,
    {
        token:true,
        loading:false,
        customDev:true
    }
    )
}